from sqlalchemy import Index
from sqlalchemy import PrimaryKeyConstraint, Sequence
from sqlalchemy.dialects.postgresql import TIMESTAMP

from tzq.extensions import db


class JobTableColumnRepare(db.Model):
    """ 比对任务对表字段进行比对及修复表 """
    __tablename__ = 'dc_job_table_column_repare_t'
    __table_args__ = (
        PrimaryKeyConstraint('job_table_column_repare_id', name='dc_job_table_column_repare_pk', comment='主键'),
        Index(
            'idx_dc_job_table_column_repare_1',
            'comp_task_id'
        ),
        Index(
            'idx_dc_job_table_column_repare_2',
            'comp_task_name'
        ),
        {'comment': '比对任务对表字段进行比对及修复表', },
    )
    job_table_column_repare_id = db.Column(
        db.BigInteger,
        Sequence('dc_job_table_column_repare_s'),
        primary_key=True,
        server_default=Sequence('dc_job_table_column_repare_s').next_value(),
        nullable=False,
        comment='主键ID'
    )
    comp_task_id = db.Column(db.BigInteger)
    comp_task_name = db.Column(db.String(300))
    schema = db.Column(db.String(100))
    table_name = db.Column(db.String(100))
    column_name = db.Column(db.String(100))
    total_check_result = db.Column(db.String(100))
    table_name_check_result = db.Column(db.String(100))
    table_name1 = db.Column(db.String(100))
    table_name2 = db.Column(db.String(100))
    table_name3 = db.Column(db.String(100))
    table_name4 = db.Column(db.String(100))
    table_name5 = db.Column(db.String(100))
    table_name6 = db.Column(db.String(100))
    table_name7 = db.Column(db.String(100))
    column_name_check_result = db.Column(db.String(100))
    column_name1 = db.Column(db.String(100))
    column_name2 = db.Column(db.String(100))
    column_name2_repair_script = db.Column(db.Text)
    column_name3 = db.Column(db.String(100))
    column_name3_repair_script = db.Column(db.Text)
    column_name4 = db.Column(db.String(100))
    column_name4_repair_script = db.Column(db.Text)
    column_name5 = db.Column(db.String(100))
    column_name5_repair_script = db.Column(db.Text)
    column_name6 = db.Column(db.String(100))
    column_name6_repair_script = db.Column(db.Text)
    column_name7 = db.Column(db.String(100))
    column_name7_repair_script = db.Column(db.Text)
    data_type_check_result = db.Column(db.String(100))
    data_type1 = db.Column(db.String(100))
    data_type2 = db.Column(db.String(100))
    data_type2_repair_script = db.Column(db.Text)
    data_type3 = db.Column(db.String(100))
    data_type3_repair_script = db.Column(db.Text)
    data_type4 = db.Column(db.String(100))
    data_type4_repair_script = db.Column(db.Text)
    data_type5 = db.Column(db.String(100))
    data_type5_repair_script = db.Column(db.Text)
    data_type6 = db.Column(db.String(100))
    data_type6_repair_script = db.Column(db.Text)
    data_type7 = db.Column(db.String(100))
    data_type7_repair_script = db.Column(db.Text)
    data_default_check_result = db.Column(db.String(100))
    data_default1 = db.Column(db.String(2000))
    data_default2 = db.Column(db.String(2000))
    data_default2_repair_script = db.Column(db.Text)
    data_default3 = db.Column(db.String(2000))
    data_default3_repair_script = db.Column(db.Text)
    data_default4 = db.Column(db.String(2000))
    data_default4_repair_script = db.Column(db.Text)
    data_default5 = db.Column(db.String(2000))
    data_default5_repair_script = db.Column(db.Text)
    data_default6 = db.Column(db.String(2000))
    data_default6_repair_script = db.Column(db.Text)
    data_default7 = db.Column(db.String(2000))
    data_default7_repair_script = db.Column(db.Text)
    pkey_check_result = db.Column(db.String(100))
    pkey1 = db.Column(db.String(100))
    pkey2 = db.Column(db.String(100))
    pkey2_repair_script = db.Column(db.Text)
    pkey3 = db.Column(db.String(100))
    pkey3_repair_script = db.Column(db.Text)
    pkey4 = db.Column(db.String(100))
    pkey4_repair_script = db.Column(db.Text)
    pkey5 = db.Column(db.String(100))
    pkey5_repair_script = db.Column(db.Text)
    pkey6 = db.Column(db.String(100))
    pkey6_repair_script = db.Column(db.Text)
    pkey7 = db.Column(db.String(100))
    pkey7_repair_script = db.Column(db.Text)
    nullable_check_result = db.Column(db.String(100))
    nullable1 = db.Column(db.String(100))
    nullable2 = db.Column(db.String(100))
    nullable2_repair_script = db.Column(db.Text)
    nullable3 = db.Column(db.String(100))
    nullable3_repair_script = db.Column(db.Text)
    nullable4 = db.Column(db.String(100))
    nullable4_repair_script = db.Column(db.Text)
    nullable5 = db.Column(db.String(100))
    nullable5_repair_script = db.Column(db.Text)
    nullable6 = db.Column(db.String(100))
    nullable6_repair_script = db.Column(db.Text)
    nullable7 = db.Column(db.String(100))
    nullable7_repair_script = db.Column(db.Text)
    table_comment_check_result = db.Column(db.String(100))
    table_comment1 = db.Column(db.Text)
    table_comment2 = db.Column(db.Text)
    table_comment2_repair_script = db.Column(db.Text)
    table_comment3 = db.Column(db.Text)
    table_comment3_repair_script = db.Column(db.Text)
    table_comment4 = db.Column(db.Text)
    table_comment4_repair_script = db.Column(db.Text)
    table_comment5 = db.Column(db.Text)
    table_comment5_repair_script = db.Column(db.Text)
    table_comment6 = db.Column(db.Text)
    table_comment6_repair_script = db.Column(db.Text)
    table_comment7 = db.Column(db.Text)
    table_comment7_repair_script = db.Column(db.Text)
    column_comment_check_result = db.Column(db.String(100))
    column_comment1 = db.Column(db.Text)
    column_comment2 = db.Column(db.Text)
    column_comment2_repair_script = db.Column(db.Text)
    column_comment3 = db.Column(db.Text)
    column_comment3_repair_script = db.Column(db.Text)
    column_comment4 = db.Column(db.Text)
    column_comment4_repair_script = db.Column(db.Text)
    column_comment5 = db.Column(db.Text)
    column_comment5_repair_script = db.Column(db.Text)
    column_comment6 = db.Column(db.Text)
    column_comment6_repair_script = db.Column(db.Text)
    column_comment7 = db.Column(db.Text)
    column_comment7_repair_script = db.Column(db.Text)
    creation_date = db.Column(TIMESTAMP(timezone=False, precision=0), nullable=False,
                              server_default=db.func.clock_timestamp(), comment='创建时间')

    def to_dict(self):
        return {
            'job_table_column_repare_id': self.job_table_column_repare_id,
            'comp_task_id': self.comp_task_id,
            'comp_task_name': self.comp_task_name,
            'schema': self.schema,
            'table_name': self.table_name,
            'column_name': self.column_name,
            'total_check_result': self.total_check_result,
            'table_name_check_result': self.table_name_check_result,
            'table_name1': self.table_name1,
            'table_name2': self.table_name2,
            'table_name3': self.table_name3,
            'table_name4': self.table_name4,
            'table_name5': self.table_name5,
            'table_name6': self.table_name6,
            'table_name7': self.table_name7,
            'column_name_check_result': self.column_name_check_result,
            'column_name1': self.column_name1,
            'column_name2': self.column_name2,
            'column_name2_repair_script': self.column_name2_repair_script,
            'column_name3': self.column_name3,
            'column_name3_repair_script': self.column_name3_repair_script,
            'column_name4': self.column_name4,
            'column_name4_repair_script': self.column_name4_repair_script,
            'column_name5': self.column_name5,
            'column_name5_repair_script': self.column_name5_repair_script,
            'column_name6': self.column_name6,
            'column_name6_repair_script': self.column_name6_repair_script,
            'column_name7': self.column_name7,
            'column_name7_repair_script': self.column_name7_repair_script,
            'data_type_check_result': self.data_type_check_result,
            'data_type1': self.data_type1,
            'data_type2': self.data_type2,
            'data_type2_repair_script': self.data_type2_repair_script,
            'data_type3': self.data_type3,
            'data_type3_repair_script': self.data_type3_repair_script,
            'data_type4': self.data_type4,
            'data_type4_repair_script': self.data_type4_repair_script,
            'data_type5': self.data_type5,
            'data_type5_repair_script': self.data_type5_repair_script,
            'data_type6': self.data_type6,
            'data_type6_repair_script': self.data_type6_repair_script,
            'data_type7': self.data_type7,
            'data_type7_repair_script': self.data_type7_repair_script,
            'data_default_check_result': self.data_default_check_result,
            'data_default1': self.data_default1,
            'data_default2': self.data_default2,
            'data_default2_repair_script': self.data_default2_repair_script,
            'data_default3': self.data_default3,
            'data_default3_repair_script': self.data_default3_repair_script,
            'data_default4': self.data_default4,
            'data_default4_repair_script': self.data_default4_repair_script,
            'data_default5': self.data_default5,
            'data_default5_repair_script': self.data_default5_repair_script,
            'data_default6': self.data_default6,
            'data_default6_repair_script': self.data_default6_repair_script,
            'data_default7': self.data_default7,
            'data_default7_repair_script': self.data_default7_repair_script,
            'pkey_check_result': self.pkey_check_result,
            'pkey1': self.pkey1,
            'pkey2': self.pkey2,
            'pkey2_repair_script': self.pkey2_repair_script,
            'pkey3': self.pkey3,
            'pkey3_repair_script': self.pkey3_repair_script,
            'pkey4': self.pkey4,
            'pkey4_repair_script': self.pkey4_repair_script,
            'pkey5': self.pkey5,
            'pkey5_repair_script': self.pkey5_repair_script,
            'pkey6': self.pkey6,
            'pkey6_repair_script': self.pkey6_repair_script,
            'pkey7': self.pkey7,
            'pkey7_repair_script': self.pkey7_repair_script,
            'nullable_check_result': self.nullable_check_result,
            'nullable1': self.nullable1,
            'nullable2': self.nullable2,
            'nullable2_repair_script': self.nullable2_repair_script,
            'nullable3': self.nullable3,
            'nullable3_repair_script': self.nullable3_repair_script,
            'nullable4': self.nullable4,
            'nullable4_repair_script': self.nullable4_repair_script,
            'nullable5': self.nullable5,
            'nullable5_repair_script': self.nullable5_repair_script,
            'nullable6': self.nullable6,
            'nullable6_repair_script': self.nullable6_repair_script,
            'nullable7': self.nullable7,
            'nullable7_repair_script': self.nullable7_repair_script,
            'table_comment_check_result': self.table_comment_check_result,
            'table_comment1': self.table_comment1,
            'table_comment2': self.table_comment2,
            'table_comment2_repair_script': self.table_comment2_repair_script,
            'table_comment3': self.table_comment3,
            'table_comment3_repair_script': self.table_comment3_repair_script,
            'table_comment4': self.table_comment4,
            'table_comment4_repair_script': self.table_comment4_repair_script,
            'table_comment5': self.table_comment5,
            'table_comment5_repair_script': self.table_comment5_repair_script,
            'table_comment6': self.table_comment6,
            'table_comment6_repair_script': self.table_comment6_repair_script,
            'table_comment7': self.table_comment7,
            'table_comment7_repair_script': self.table_comment7_repair_script,
            'column_comment_check_result': self.column_comment_check_result,
            'column_comment1': self.column_comment1,
            'column_comment2': self.column_comment2,
            'column_comment2_repair_script': self.column_comment2_repair_script,
            'column_comment3': self.column_comment3,
            'column_comment3_repair_script': self.column_comment3_repair_script,
            'column_comment4': self.column_comment4,
            'column_comment4_repair_script': self.column_comment4_repair_script,
            'column_comment5': self.column_comment5,
            'column_comment5_repair_script': self.column_comment5_repair_script,
            'column_comment6': self.column_comment6,
            'column_comment6_repair_script': self.column_comment6_repair_script,
            'column_comment7': self.column_comment7,
            'column_comment7_repair_script': self.column_comment7_repair_script,
            'creation_date': self.creation_date.strftime('%Y-%m-%d %H:%M:%S')
        }
